<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx"
    xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
    xmlns:schema_1_0="http://schemas.microsoft.com/ado/2006/04/edm"
    xmlns:schema_1_1="http://schemas.microsoft.com/ado/2007/05/edm"
    xmlns:schema_1_2="http://schemas.microsoft.com/ado/2008/09/edm"
    xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">

  <xsl:output method="text"/>

  <!-- Default service URI passed externally -->
  <xsl:param name="serviceName"/>
 <xsl:template match="/">&lt;?php
<!--
/*
    Copyright 2011 Persistent Systems Limited
    Licensed under the New BSD License scheme.;
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
    http://www.opensource.org/licenses/bsd-license.php
*/
    /**
     * This code was generated by the tool 'MySQLConnector.php'.
     * Runtime Version:1.0
     *
     * Changes to this file may cause incorrect behavior and will be lost if
     * the code is regenerated.
     */
-->
 /**
 * Implementation of IServiceProvider.
 *
 * PHP version 5.3
 *
 * @category  Service
 * @package   Service_<xsl:value-of select="$serviceName"/>
 * @author    Yash K. Kothari &lt;odataphpproducer_alias@microsoft.com&gt;
 * @copyright 2011 Microsoft Corp. (http://www.microsoft.com)
 * @license   New BSD license, (http://www.opensource.org/licenses/bsd-license.php)
 * @version   SVN: 1.0
 * @link      http://odataphpproducer.codeplex.com
 * 
 */
use ODataProducer\Configuration\EntitySetRights;
require_once 'ODataProducer/IDataService.php';
require_once 'ODataProducer/IRequestHandler.php';
require_once 'ODataProducer/DataService.php';
require_once 'ODataProducer/IServiceProvider.php';
use ODataProducer\Configuration\DataServiceProtocolVersion;
use ODataProducer\Configuration\DataServiceConfiguration;
use ODataProducer\IServiceProvider;
use ODataProducer\DataService;
<xsl:apply-templates select="/configuration/rules" />
?&gt;
</xsl:template>

<xsl:template match="configuration/rules">
require_once '<xsl:value-of select="$serviceName"/>Metadata.php';
require_once '<xsl:value-of select="$serviceName"/>QueryProvider.php';
<xsl:if test="queryProviderVersion = 2">require_once '<xsl:value-of select="$serviceName"/>DSExpressionProvider.php';
</xsl:if>
/**
 * <xsl:value-of select="$serviceName"/>DataService that implements IServiceProvider.
 * 
 * @category  Service
 * @package   Service_<xsl:value-of select="$serviceName"/>
 * @author    Yash K Kothari &lt;odataphpproducer_alias@microsoft.com&gt;
 * @copyright 2011 Microsoft Corp. (http://www.microsoft.com)
 * @license   New BSD license, (http://www.opensource.org/licenses/bsd-license.php)
 * @version   Release: 1.0
 * @link      http://odataphpproducer.codeplex.com
 */
class <xsl:value-of select="$serviceName"/>DataService extends DataService implements IServiceProvider
{
    private $_<xsl:value-of select="$serviceName"/>Metadata = null;
    private $_<xsl:value-of select="$serviceName"/>QueryProvider = null;
    private $_<xsl:value-of select="$serviceName"/>ExpressionProvider = null;
    
    /**
     * This method is called only once to initialize service-wide policies
     * 
     * @param DataServiceConfiguration &amp;$config Data service configuration object
     * 
     * @return void
     */
    public function initializeService(DataServiceConfiguration &amp;$config)
    {   <xsl:if test="nameEntitySetPageSize != 'null' and pageSizeEntitySetPageSize != 'null'">
        $config->setEntitySetPageSize('<xsl:value-of select="nameEntitySetPageSize"/>', <xsl:value-of select="pageSizeEntitySetPageSize"/>);</xsl:if>
        <xsl:if test="nameEntitySetAccessRule != 'null' and rightsEntitySetAccessRule != 'null'">
        $config->setEntitySetAccessRule('<xsl:value-of select="nameEntitySetAccessRule"/>', EntitySetRights::<xsl:value-of select="rightsEntitySetAccessRule"/>);</xsl:if>
        <xsl:if test="acceptCountRequest != 'null'">
        $config->setAcceptCountRequests(<xsl:value-of select="acceptCountRequest"/>);</xsl:if>
        <xsl:if test="acceptProjectionRequest != 'null'">
        $config->setAcceptProjectionRequests(<xsl:value-of select="acceptProjectionRequest"/>);</xsl:if>
        <xsl:if test="maxDataServiceVersion != 'null'">
        $config->setMaxDataServiceVersion(DataServiceProtocolVersion::<xsl:value-of select="maxDataServiceVersion"/>);</xsl:if>
        <xsl:if test="maxExpandCount != 'null'">
        $config->setMaxExpandCount(<xsl:value-of select="maxExpandCount"/>);</xsl:if>
        <xsl:if test="maxExpandDepth != 'null'">
        $config->setMaxExpandDepth(<xsl:value-of select="maxExpandDepth"/>);</xsl:if>
        <xsl:if test="maxResultsPerCollection != 'null'">
        $config->setMaxResultsPerCollection(<xsl:value-of select="maxResultsPerCollection"/>);</xsl:if>
        <xsl:if test="useVerboseErrors != 'null'">
        $config->setUseVerboseErrors(<xsl:value-of select="useVerboseErrors"/>);</xsl:if>
    }

    /**
     * Get the service like IDataServiceMetadataProvider, IDataServiceQueryProvider,
     * IDataServiceStreamProvider
     * 
     * @param String $serviceType Type of service IDataServiceMetadataProvider, 
     *                            IDataServiceQueryProvider,
     *                            IDataServiceStreamProvider
     * 
     * @see library/ODataProducer/ODataProducer.IServiceProvider::getService()
     * @return object
     */
    public function getService($serviceType)
    {
        <xsl:if test="queryProviderVersion = 2">
        if (($serviceType === 'IDataServiceMetadataProvider') 
            || ($serviceType === 'IDataServiceQueryProvider2') 
            || ($serviceType === 'IDataServiceStreamProvider')
        ) {
            if (is_null($this->_<xsl:value-of select="$serviceName"/>ExpressionProvider)) {
                $this->_<xsl:value-of select="$serviceName"/>ExpressionProvider = new <xsl:value-of select="$serviceName"/>DSExpressionProvider();
            }
        }
        </xsl:if>
        if ($serviceType === 'IDataServiceMetadataProvider') {
            if (is_null($this->_<xsl:value-of select="$serviceName"/>Metadata)) {
                $this->_<xsl:value-of select="$serviceName"/>Metadata = Create<xsl:value-of select="$serviceName"/>Metadata::create();
            }
            return $this->_<xsl:value-of select="$serviceName"/>Metadata;
        } else if ($serviceType === 'IDataServiceQueryProvider2') {
            if (is_null($this->_<xsl:value-of select="$serviceName"/>QueryProvider)) {
                $this->_<xsl:value-of select="$serviceName"/>QueryProvider = new <xsl:value-of select="$serviceName"/>QueryProvider();
            }
            return $this->_<xsl:value-of select="$serviceName"/>QueryProvider;
        } else if ($serviceType === 'IDataServiceStreamProvider') {
            return new <xsl:value-of select="$serviceName"/>StreamProvider();
        }
        return null;
    }
}
</xsl:template>
</xsl:stylesheet>
